﻿<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
	<meta name="fhdb" content="true">
    <title>百瑞花苑-修改密码</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css"> 
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../css/bootstrapValidator.css"/>
    <script type="text/javascript" src="../jquery/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="../jquery/bootstrap.min.js"></script>
    <script type="text/javascript" src="../jquery/bootstrapValidator.js"></script>
    <script src="../jquery/jquery.form.min.js" type="text/javascript"></script>
</head>
<body>
    <div class="phoneError"></div>
    <form id="defaultForm">
        <div class="backBox" onClick="javascript:history.back(-1);">
            <span class="glyphicon glyphicon-chevron-left"></span>
        </div>
        <div class="topTitle">修改密码</div>
        <div class="bigBox">
            <div class="passBox form-group">
                <span class="glyphicon glyphicon-lock"></span><input type="oldPassword" id="oldPassword" name="oldPassword" placeholder="请输入旧密码"/>
            </div>
            <div class="passBox form-group">
                <span class="glyphicon glyphicon-lock"></span><input type="password" id="password" name="password" placeholder="请输入新密码"/>
            </div>
            <div class="passBox form-group">
                <span class="glyphicon glyphicon-lock"></span><input type="password" name="repassword" placeholder="请确认新密码"/>
            </div>
            <div class="form-group">
                <button type="submit" class="btn btnBox" id="btnBox">提交</button>
            </div>
        </div>
    </form>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#defaultForm').bootstrapValidator({
                fields: {
                    password: {
                        validators: {
                            notEmpty: {
                                message: '密码不能为空'
                            },
                            stringLength: {
                                min: 8,
                                max: 16,
                                message: '长度必须在8到16之间'
                            },
                            regexp: {
                                regexp: /^[a-zA-Z0-9_\.]+$/,
                                message: '用户名只能由字母、数字、点和下划线组成'
                            }
                        }
                    },
                    repassword: {
                        validators: {
                            notEmpty: {
                                message: '密码不能为空'
                            },
                            stringLength: {
                                min: 8,
                                max: 16,
                                message: '长度必须在8到16之间'
                            },
                            identical: {//相同
                                field: 'password',
                                message: '两次密码不一致'
                            },
                            regexp: {//匹配规则
                                regexp: /^[a-zA-Z0-9_\.]+$/,
                                message: '用户名只能由字母、数字、点和下划线组成'
                            }
                        }
                    }
                }
            });
            //提交表单数据
            $('#btnBox').click(function (event) {
                /* Act on the event */
                /*手动验证表单，当是普通按钮时。*/
                $('#defaultForm').data('bootstrapValidator').validate(); //启用验证
                var flag = $('#defaultForm').data('bootstrapValidator').isValid()//验证是否通过true/false
                var password = $('#password').val();
                var oldPassword = $('#oldPassword').val();
                if (flag) {
                    $.ajax({
                        type: "text",
                        url: "/order/changepwd",
                        data:{"changepwd":password,"oldPassword":oldPassword},
                        dataType: "json",
                        success: function (result) {
                            alert("成功");
                            window.location.href = "../main/indexshop.html";

                            // if (result.success == false) {
                            //     if (result.msg == "_timeout") {
                            //         $('.phoneError').text("操作超时，请重新登陆！");
                            //         var top = ($(window).height() - $('.phoneError').height()) / 2;
                            //         var left = ($(window).width() - $('.phoneError').width()) / 2;
                            //         var scrollTop = $(document).scrollTop();
                            //         var scrollLeft = $(document).scrollLeft();
                            //         $('.phoneError').css({ position: 'absolute', 'top': top + scrollTop, left: left + scrollLeft }).show();
                            //         setTimeout(function () {
                            //             $('.phoneError').hide();
                            //             window.location.href = "../UserLogin/Login.html";
                            //         }, 2000)
                            //         return;
                            //     }
                            //     $('.phoneError').text(result.msg);
                            //     var top = ($(window).height() - $('.phoneError').height()) / 2;
                            //     var left = ($(window).width() - $('.phoneError').width()) / 2;
                            //     var scrollTop = $(document).scrollTop();
                            //     var scrollLeft = $(document).scrollLeft();
                            //     $('.phoneError').css({ position: 'absolute', 'top': top + scrollTop, left: left + scrollLeft }).show();
                            //     setTimeout(function () {
                            //         $('.phoneError').hide();
                            //         window.location.reload();
                            //     }, 2000)
                            // }
                            // else {
                            //     $('.phoneError').text(result.msg);
                            //     var top = ($(window).height() - $('.phoneError').height()) / 2;
                            //     var left = ($(window).width() - $('.phoneError').width()) / 2;
                            //     var scrollTop = $(document).scrollTop();
                            //     var scrollLeft = $(document).scrollLeft();
                            //     $('.phoneError').css({ position: 'absolute', 'top': top + scrollTop, left: left + scrollLeft }).show();
                            //     setTimeout(function () {
                            //         $('.phoneError').hide();
                            //         window.location.href = "../main/indexshop.html";
                            //     }, 2000)
                            // }
                        }
                    });
                }
            });

        });
        </script>
</body>
</html>